﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

using Google.GData.Client;
using DataSources.Holder;

namespace CodeBrigadeTE
{
    public partial class ProjectsList : UserControl
    {
        private IDataHolder dataSource = null;

        public IDataHolder DataSource
        {
            set
            {
                if (dataSource != value)
                {
                    dataSource = value;
                    OnDataSourceChanged();
                }
            }
            get
            {
                return dataSource;
            }
        }

        public ProjectsList()
        {
            InitializeComponent();
        }

        private void OnDataSourceChanged()
        {
            if (dataSource != null)
            {
                setSpreadsheetListView(dataSource.GetEntries());
            }
            else
            {
                this.listView.SelectedItems.Clear();
                this.listView.Items.Clear();
            }
        }

        void setSpreadsheetListView(Hashtable projects)
        {
            this.listView.Items.Clear();
            foreach (DictionaryEntry project in projects)
            {
                ListViewItem item = new ListViewItem(((DataSources.SpreadsheetInfo)project.Value).title);
                item.Tag = project.Key;
                this.listView.Items.Add(item);
            }
        }
    }
}
